home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Program: aeclient
- ** - an apple event generator program for a TCP host
- ** Author: cf haupt
- ** Created: 09-apr-1992
- **
- */
-
- #include <stdio.h>
- #include "tcpae.h"
-
- /*
- **
- */
- main (int argc, char *argv[])
- {
- int i,
- simple = 0;
- short context;
-
- char *hostname = 0,
- *oapp_sig = 0, *quit_sig = 0, *script_sig = 0;
-
- if (argc < 2) {
- fprintf (stderr, "syntax: %s [-host name] [-quit signature] ", argv[0]);
- fprintf (stderr, "[-oapp signature] [-stat] \n");
- fprintf (stderr, "[-dosc signature < script]\n");
- fprintf (stderr,
- "The default host is given by the TCPAEGATEHOST enviroment variable.\n");
- exit (1);
- }
-
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
- if (strncmp (argv[i], "-host", 5) == 0) {
- hostname = argv[++i];
- }
- else if (strncmp(argv[i],"-stat",5) == 0)
- simple |= 0x01;
- else if (strncmp(argv[i],"-oapp",5) == 0){
- oapp_sig = argv[++i];
- simple |= 0x02;
- }
- else if (strncmp(argv[i],"-quit",5) == 0){
- quit_sig = argv[++i];
- simple |= 0x04;
- }
- else if (strncmp(argv[i],"-do",3) == 0){
- script_sig = argv[++i];
- simple |= 0x08;
- }
- }
- }
-
- /* decide if we should open link*/
- if (simple)
- {
- TCPAEInit();
- fprintf(stderr, "Opening gate %d\n", TCPAEOpenGate(&context, hostname));
-
- if (context != kNoContext)
- {
- StatusRec statRec;
- /* do commands found on command line */
- if (simple & 0x01)
- {
- TCPAEGateStatus (context,&statRec);
- fprintf(stderr,
- "Returned Status:\nversion: %d\nfilter:%d\npackets:%d\n",
- statRec.version, statRec.filterFlags, statRec.packetsServed);
- }
- if (simple & 0x02) TCPAESendOAPP(context, oapp_sig);
- if (simple & 0x04) TCPAESendQUIT(context, quit_sig);
- if (simple & 0x08)
- {
- char c; int i; char *script;
- script = (char *) calloc(1,sizeof(char));
- while ((c = getchar()) != EOF)
- {
- script[i++] = c;
- realloc(script, strlen(script) + 1);
- }
- TCPAESendDOSC(context, script_sig, script);
- free(script);
- }
-
- /* close the connection is it was open */
- TCPAECloseGate(context);
- }
- }
- }
-